package o;

import com.huawei.appmarket.service.deamon.download.remote.DownloadAgentService;
import com.huawei.hwid.core.datatype.UserInfo;
import java.io.Reader;
import java.util.ArrayList;
import java.util.List;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

public class gbv extends gco {
    static final /* synthetic */ boolean ʻ = (!gbv.class.desiredAssertionStatus());
    static final String[] ʼ = new String[]{UserInfo.ADDRESS, "applet", "area", "article", "aside", "base", "basefont", "bgsound", "blockquote", "body", "br", "button", "caption", "center", "col", "colgroup", DownloadAgentService.COMMAND_ARG, "dd", "details", "dir", "div", "dl", "dt", "embed", "fieldset", "figcaption", "figure", "footer", "form", "frame", "frameset", "h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hgroup", "hr", "html", "iframe", "img", "input", "isindex", "li", "link", "listing", "marquee", "menu", "meta", "nav", "noembed", "noframes", "noscript", "object", "ol", "p", "param", "plaintext", "pre", "script", "section", "select", "style", "summary", "table", "tbody", "td", "textarea", "tfoot", "th", "thead", "title", "tr", "ul", "wbr", "xmp"};
    static final String[] ˊ = new String[]{"optgroup", "option"};
    static final String[] ˋ = new String[]{"ol", "ul"};
    static final String[] ˎ = new String[]{"applet", "caption", "html", "marquee", "object", "table", "td", "th"};
    static final String[] ˏ = new String[]{"button"};
    static final String[] ॱ = new String[]{"html", "table"};
    static final String[] ᐝ = new String[]{"dd", "dt", "li", "optgroup", "option", "p", "rp", "rt"};
    private gbr ʼॱ;
    private List<String> ʽॱ;
    private ArrayList<Element> ʾ;
    private Element ʿ;
    private g ˈ;
    private boolean ˉ;
    private boolean ˊˋ;
    private String[] ˊᐝ = new String[]{null};
    private boolean ˋˊ;
    private gce ॱˋ;
    private Element ॱˎ;
    private boolean ॱᐝ;
    private gce ᐝॱ;

    gcd ˊ() {
        return gcd.ˋ;
    }

    protected void ˋ(Reader reader, String str, gcb o_gcb) {
        super.ˋ(reader, str, o_gcb);
        this.ᐝॱ = gce.Initial;
        this.ॱˋ = null;
        this.ॱᐝ = false;
        this.ॱˎ = null;
        this.ʼॱ = null;
        this.ʿ = null;
        this.ʾ = new ArrayList();
        this.ʽॱ = new ArrayList();
        this.ˈ = new g();
        this.ˉ = true;
        this.ˊˋ = false;
        this.ˋˊ = false;
    }

    protected boolean ˎ(gcg o_gcg) {
        this.ˋॱ = o_gcg;
        return this.ᐝॱ.ॱ(o_gcg, this);
    }

    boolean ˏ(gcg o_gcg, gce o_gce) {
        this.ˋॱ = o_gcg;
        return o_gce.ॱ(o_gcg, this);
    }

    void ˎ(gce o_gce) {
        this.ᐝॱ = o_gce;
    }

    gce ˏ() {
        return this.ᐝॱ;
    }

    void ॱ() {
        this.ॱˋ = this.ᐝॱ;
    }

    gce ˎ() {
        return this.ॱˋ;
    }

    void ˋ(boolean z) {
        this.ˉ = z;
    }

    boolean ˋ() {
        return this.ˉ;
    }

    Document ᐝ() {
        return this.ॱˊ;
    }

    String ॱॱ() {
        return this.ˏॱ;
    }

    void ˏ(Element element) {
        if (!this.ॱᐝ) {
            String ˏ = element.ˏ("href");
            if (ˏ.length() != 0) {
                this.ˏॱ = ˏ;
                this.ॱᐝ = true;
                this.ॱˊ.ˎ(ˏ);
            }
        }
    }

    boolean ʼ() {
        return this.ˋˊ;
    }

    void ˏ(gce o_gce) {
        if (this.ॱॱ.ˏ().ˊ()) {
            this.ॱॱ.ˏ().add(new gcc(this.ʽ.ˎ(), "Unexpected token [%s] when in state [%s]", this.ˋॱ.ˎ(), o_gce));
        }
    }

    Element ˊ(i iVar) {
        if (iVar.ᐝॱ()) {
            Element ˋ = ˋ(iVar);
            this.ͺ.add(ˋ);
            this.ˊॱ.ˎ(gcf.Data);
            this.ˊॱ.ˎ(this.ˈ.ॱˊ().ˊ(ˋ.ˊॱ()));
            return ˋ;
        }
        ˋ = new Element(gcj.ˋ(iVar.ॱˎ(), this.ʻॱ), this.ˏॱ, this.ʻॱ.ˏ(iVar.attrValueRefName));
        ˋ(ˋ);
        return ˋ;
    }

    Element ˋ(String str) {
        Element element = new Element(gcj.ˋ(str, this.ʻॱ), this.ˏॱ);
        ˋ(element);
        return element;
    }

    void ˋ(Element element) {
        ˊ((gbq) element);
        this.ͺ.add(element);
    }

    Element ˋ(i iVar) {
        gcj ˋ = gcj.ˋ(iVar.ॱˎ(), this.ʻॱ);
        gbq element = new Element(ˋ, this.ˏॱ, iVar.attrValueRefName);
        ˊ(element);
        if (iVar.ᐝॱ()) {
            if (!ˋ.ʽ()) {
                ˋ.ʻ();
            } else if (!ˋ.ˊ()) {
                this.ˊॱ.ˏ("Tag cannot be self closing; not a void tag");
            }
        }
        return element;
    }

    gbr ˏ(i iVar, boolean z) {
        gbq o_gbr = new gbr(gcj.ˋ(iVar.ॱˎ(), this.ʻॱ), this.ˏॱ, iVar.attrValueRefName);
        ˊ((gbr) o_gbr);
        ˊ(o_gbr);
        if (z) {
            this.ͺ.add(o_gbr);
        }
        return o_gbr;
    }

    void ˊ(b bVar) {
        ˊ(new gbn(bVar.ॱˊ()));
    }

    void ॱ(d dVar) {
        gbq o_gbp;
        Element ˊˊ = ˊˊ();
        String ˊॱ = ˊˊ.ˊॱ();
        String ॱˊ = dVar.ॱˊ();
        if (dVar.ˊॱ()) {
            o_gbp = new gbp(ॱˊ);
        } else if (ˊॱ.equals("script") || ˊॱ.equals("style")) {
            o_gbp = new gbm(ॱˊ);
        } else {
            o_gbp = new gbx(ॱˊ);
        }
        ˊˊ.ˊ(o_gbp);
    }

    private void ˊ(gbq o_gbq) {
        if (this.ͺ.size() == 0) {
            this.ॱˊ.ˊ(o_gbq);
        } else if (ॱˋ()) {
            ˎ(o_gbq);
        } else {
            ˊˊ().ˊ(o_gbq);
        }
        if ((o_gbq instanceof Element) && ((Element) o_gbq).ʻॱ().ᐝ() && this.ʼॱ != null) {
            this.ʼॱ.ˋ((Element) o_gbq);
        }
    }

    Element ʻ() {
        return (Element) this.ͺ.remove(this.ͺ.size() - 1);
    }

    void ˎ(Element element) {
        this.ͺ.add(element);
    }

    ArrayList<Element> ʽ() {
        return this.ͺ;
    }

    boolean ॱ(Element element) {
        return ˏ(this.ͺ, element);
    }

    private boolean ˏ(ArrayList<Element> arrayList, Element element) {
        for (int size = arrayList.size() - 1; size >= 0; size--) {
            if (((Element) arrayList.get(size)) == element) {
                return true;
            }
        }
        return false;
    }

    Element ˏ(String str) {
        for (int size = this.ͺ.size() - 1; size >= 0; size--) {
            Element element = (Element) this.ͺ.get(size);
            if (element.ˋॱ().equals(str)) {
                return element;
            }
        }
        return null;
    }

    boolean ˊ(Element element) {
        for (int size = this.ͺ.size() - 1; size >= 0; size--) {
            if (((Element) this.ͺ.get(size)) == element) {
                this.ͺ.remove(size);
                return true;
            }
        }
        return false;
    }

    void ˊ(String str) {
        int size = this.ͺ.size() - 1;
        while (size >= 0) {
            Element element = (Element) this.ͺ.get(size);
            this.ͺ.remove(size);
            if (!element.ˋॱ().equals(str)) {
                size--;
            } else {
                return;
            }
        }
    }

    void ˎ(String... strArr) {
        int size = this.ͺ.size() - 1;
        while (size >= 0) {
            Element element = (Element) this.ͺ.get(size);
            this.ͺ.remove(size);
            if (!gbk.ˏ(element.ˋॱ(), strArr)) {
                size--;
            } else {
                return;
            }
        }
    }

    void ॱ(String str) {
        int size = this.ͺ.size() - 1;
        while (size >= 0 && !((Element) this.ͺ.get(size)).ˋॱ().equals(str)) {
            this.ͺ.remove(size);
            size--;
        }
    }

    void ˏॱ() {
        ॱ("table");
    }

    void ॱˊ() {
        ॱ("tbody", "tfoot", "thead", "template");
    }

    void ˋॱ() {
        ॱ("tr", "template");
    }

    private void ॱ(String... strArr) {
        int size = this.ͺ.size() - 1;
        while (size >= 0) {
            Element element = (Element) this.ͺ.get(size);
            if (!gbk.ˊ(element.ˋॱ(), strArr) && !element.ˋॱ().equals("html")) {
                this.ͺ.remove(size);
                size--;
            } else {
                return;
            }
        }
    }

    Element ʼ(Element element) {
        if (ʻ || ॱ(element)) {
            for (int size = this.ͺ.size() - 1; size >= 0; size--) {
                if (((Element) this.ͺ.get(size)) == element) {
                    return (Element) this.ͺ.get(size - 1);
                }
            }
            return null;
        }
        throw new AssertionError();
    }

    void ˋ(Element element, Element element2) {
        int lastIndexOf = this.ͺ.lastIndexOf(element);
        gbj.ˋ(lastIndexOf != -1);
        this.ͺ.add(lastIndexOf + 1, element2);
    }

    void ॱ(Element element, Element element2) {
        ˊ(this.ͺ, element, element2);
    }

    private void ˊ(ArrayList<Element> arrayList, Element element, Element element2) {
        int lastIndexOf = arrayList.lastIndexOf(element);
        gbj.ˋ(lastIndexOf != -1);
        arrayList.set(lastIndexOf, element2);
    }

    void ͺ() {
        Object obj = null;
        int size = this.ͺ.size() - 1;
        while (size >= 0) {
            Element element = (Element) this.ͺ.get(size);
            if (size == 0) {
                obj = 1;
                element = this.ʿ;
            }
            String ˋॱ = element.ˋॱ();
            if ("select".equals(ˋॱ)) {
                ˎ(gce.InSelect);
                return;
            } else if ("td".equals(ˋॱ) || ("th".equals(ˋॱ) && obj == null)) {
                ˎ(gce.InCell);
                return;
            } else if ("tr".equals(ˋॱ)) {
                ˎ(gce.InRow);
                return;
            } else if ("tbody".equals(ˋॱ) || "thead".equals(ˋॱ) || "tfoot".equals(ˋॱ)) {
                ˎ(gce.InTableBody);
                return;
            } else if ("caption".equals(ˋॱ)) {
                ˎ(gce.InCaption);
                return;
            } else if ("colgroup".equals(ˋॱ)) {
                ˎ(gce.InColumnGroup);
                return;
            } else if ("table".equals(ˋॱ)) {
                ˎ(gce.InTable);
                return;
            } else if ("head".equals(ˋॱ)) {
                ˎ(gce.InBody);
                return;
            } else if ("body".equals(ˋॱ)) {
                ˎ(gce.InBody);
                return;
            } else if ("frameset".equals(ˋॱ)) {
                ˎ(gce.InFrameset);
                return;
            } else if ("html".equals(ˋॱ)) {
                ˎ(gce.BeforeHead);
                return;
            } else if (obj != null) {
                ˎ(gce.InBody);
                return;
            } else {
                size--;
            }
        }
    }

    private boolean ॱ(String str, String[] strArr, String[] strArr2) {
        this.ˊᐝ[0] = str;
        return ˎ(this.ˊᐝ, strArr, strArr2);
    }

    private boolean ˎ(String[] strArr, String[] strArr2, String[] strArr3) {
        int size = this.ͺ.size() - 1;
        if (size > 100) {
            int i = size - 100;
        } else {
            boolean z = false;
        }
        while (size >= i) {
            String ˋॱ = ((Element) this.ͺ.get(size)).ˋॱ();
            if (gbk.ˏ(ˋॱ, strArr)) {
                return true;
            }
            if (gbk.ˏ(ˋॱ, strArr2)) {
                return false;
            }
            if (strArr3 != null && gbk.ˏ(ˋॱ, strArr3)) {
                return false;
            }
            size--;
        }
        return false;
    }

    boolean ˋ(String[] strArr) {
        return ˎ(strArr, ˎ, null);
    }

    boolean ˎ(String str) {
        return ॱ(str, null);
    }

    boolean ॱ(String str, String[] strArr) {
        return ॱ(str, ˎ, strArr);
    }

    boolean ʼ(String str) {
        return ॱ(str, ˋ);
    }

    boolean ʻ(String str) {
        return ॱ(str, ˏ);
    }

    boolean ᐝ(String str) {
        return ॱ(str, ॱ, null);
    }

    boolean ʽ(String str) {
        for (int size = this.ͺ.size() - 1; size >= 0; size--) {
            String ˋॱ = ((Element) this.ͺ.get(size)).ˋॱ();
            if (ˋॱ.equals(str)) {
                return true;
            }
            if (!gbk.ˏ(ˋॱ, ˊ)) {
                return false;
            }
        }
        gbj.ˏ("Should not be reachable");
        return false;
    }

    void ʻ(Element element) {
        this.ॱˎ = element;
    }

    Element ˊॱ() {
        return this.ॱˎ;
    }

    boolean ॱˋ() {
        return this.ˊˋ;
    }

    void ˏ(boolean z) {
        this.ˊˋ = z;
    }

    gbr ॱˎ() {
        return this.ʼॱ;
    }

    void ˊ(gbr o_gbr) {
        this.ʼॱ = o_gbr;
    }

    void ॱᐝ() {
        this.ʽॱ = new ArrayList();
    }

    List<String> ʻॱ() {
        return this.ʽॱ;
    }

    void ॱॱ(String str) {
        while (str != null && !ˊˊ().ˋॱ().equals(str) && gbk.ˏ(ˊˊ().ˋॱ(), ᐝ)) {
            ʻ();
        }
    }

    void ᐝॱ() {
        ॱॱ(null);
    }

    boolean ॱॱ(Element element) {
        return gbk.ˏ(element.ˋॱ(), ʼ);
    }

    Element ˈ() {
        return this.ʾ.size() > 0 ? (Element) this.ʾ.get(this.ʾ.size() - 1) : null;
    }

    Element ʽॱ() {
        int size = this.ʾ.size();
        if (size > 0) {
            return (Element) this.ʾ.remove(size - 1);
        }
        return null;
    }

    void ʽ(Element element) {
        int i = 0;
        int size = this.ʾ.size() - 1;
        while (size >= 0) {
            Element element2 = (Element) this.ʾ.get(size);
            if (element2 == null) {
                break;
            }
            int i2;
            if (ˎ(element, element2)) {
                i2 = i + 1;
            } else {
                i2 = i;
            }
            if (i2 == 3) {
                this.ʾ.remove(size);
                break;
            } else {
                size--;
                i = i2;
            }
        }
        this.ʾ.add(element);
    }

    private boolean ˎ(Element element, Element element2) {
        return element.ˋॱ().equals(element2.ˋॱ()) && element.ͺ().equals(element2.ͺ());
    }

    void ʿ() {
        Element ˈ = ˈ();
        if (ˈ != null && !ॱ(ˈ)) {
            Object obj;
            int i;
            Element element;
            int i2;
            int size = this.ʾ.size();
            int i3 = size - 1;
            while (i3 != 0) {
                i3--;
                Element element2 = (Element) this.ʾ.get(i3);
                if (element2 == null) {
                    obj = null;
                    i = i3;
                    element = element2;
                    i2 = i;
                    break;
                } else if (ॱ(element2)) {
                    obj = null;
                    i = i3;
                    element = element2;
                    i2 = i;
                    break;
                } else {
                    ˈ = element2;
                }
            }
            i2 = i3;
            element = ˈ;
            obj = 1;
            while (true) {
                if (obj == null) {
                    i3 = i2 + 1;
                    i = i3;
                    element = (Element) this.ʾ.get(i3);
                    i2 = i;
                }
                gbj.ˋ(r1);
                ˈ = ˋ(r1.ˋॱ());
                ˈ.ͺ().ˎ(r1.ͺ());
                this.ʾ.set(i2, ˈ);
                if (i2 != size - 1) {
                    obj = null;
                } else {
                    return;
                }
            }
        }
    }

    void ʾ() {
        while (!this.ʾ.isEmpty()) {
            if (ʽॱ() == null) {
                return;
            }
        }
    }

    void ᐝ(Element element) {
        for (int size = this.ʾ.size() - 1; size >= 0; size--) {
            if (((Element) this.ʾ.get(size)) == element) {
                this.ʾ.remove(size);
                return;
            }
        }
    }

    boolean ˊॱ(Element element) {
        return ˏ(this.ʾ, element);
    }

    Element ˏॱ(String str) {
        int size = this.ʾ.size() - 1;
        while (size >= 0) {
            Element element = (Element) this.ʾ.get(size);
            if (element == null) {
                break;
            } else if (element.ˋॱ().equals(str)) {
                return element;
            } else {
                size--;
            }
        }
        return null;
    }

    void ˊ(Element element, Element element2) {
        ˊ(this.ʾ, element, element2);
    }

    void ʼॱ() {
        this.ʾ.add(null);
    }

    void ˎ(gbq o_gbq) {
        Element element;
        int i;
        Element ˏ = ˏ("table");
        if (ˏ == null) {
            element = (Element) this.ͺ.get(0);
            i = 0;
        } else if (ˏ.ᐝॱ() != null) {
            element = ˏ.ᐝॱ();
            i = 1;
        } else {
            element = ʼ(ˏ);
            i = 0;
        }
        if (i != 0) {
            gbj.ˋ((Object) ˏ);
            ˏ.ˋ(o_gbq);
            return;
        }
        element.ˊ(o_gbq);
    }

    public String toString() {
        return "TreeBuilder{currentToken=" + this.ˋॱ + ", state=" + this.ᐝॱ + ", currentElement=" + ˊˊ() + '}';
    }
}
